

import React from 'react';
import { useEffect } from 'react';
import c from './css/index.module.scss'
import axios from "axios"
import { useState } from 'react';
import { Link } from 'react-router-dom';
import { EditOutlined } from '@ant-design/icons';

export default function Index() {

  const [response, setRes] = useState([{ email: "" }])
  // 数据是否请求成功的状态
  const [state1, setBool] = useState(false)


  useEffect(() => {
    // let fn= ()=>{
    const res = axios.get("/works", { params: { email: "123@qq.com" } }).then((res) => {
      // console.log(11,res.data[0].email,res.data,res.data[0][0].username);
      setRes(res.data)

      setBool(true)
      console.log(2222);
      // console.log(response,22,response[0]);
    })

  }, [])
  console.log(response, 33, response[0]);
  return (
    <div className={c['box']}>
      <div className={c['zong']}>
        <div className={c['left']}>
          {
            state1 ? (
              <div className={c['left_zong']}>
                <h4>{response[0][0].username}</h4>
                <img src={response[0][0].avatar} alt="" />
                <p><EditOutlined /><Link to="/personal">编辑资料</Link></p>
              </div>

            ) : (<div>加载中</div>)
          }
        </div>
        <div className={c['right']}>
          {
            state1 ? (
              <div className={c['right_zong']}>
                <ul>
                  <li className={c['work']}>作品</li>
                  <li><Link to="/bookRelease">新建作品</Link></li>
                </ul>
                <div className={c['book_zong']}>
                  {
                    response[1][0] ? (<div className={c['single_zong']}>
                      {response[1].map((el, index) => {
                        return (
                          <div key={index} className={c['singleb']}>
                            <div><img src={el.cover} alt="" /></div>
                            <div><span> {el.name1}</span> <Link to={{ pathname: "/updata", search: `boookID=${el.bookID}` }}>更新</Link></div>
                          </div>
                        )
                      })}
                    </div>) : (<div className={c['nowork']}>
                      <span >您尚无作品-</span>
                      <button><Link to="/bookRelease">立即投稿</Link></button>
                    </div>)
                  }
                  {/* 单本书 */}
                  {/* {response[1].map((el, index) => {
                    return (
                      <div key={index} className={c['singleb']}>
                        <div><img src={el.cover} alt="" /></div>
                        <div><span> {el.name1}</span> <Link to={{ pathname: "/updata", search: `boookID=${el.bookID}` }}>更新</Link></div>
                      </div>
                    )
                  })} */}
                </div>
              </div>
            ) :
              (<div>加载中</div>)
          }
        </div>
      </div>
    </div>
  )
}
